package com.topvision.face;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.kernal.demo.plateid.R;
import com.topvision.bureau.presenter.RegModePresenter;
import com.topvision.commomsdk.TouchInterface;
import com.topvision.voicesdk.BaseVoiceActivity;
import com.topvision.voicesdk.VoiceInterface;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 车牌识别选择模式类
 * User: jack(jackgu@topvision-cv.com)
 * Date: 2016-12-02
 * Time: 11:23
 */
public class ChooseFaceModeActivity extends BaseVoiceActivity implements TouchInterface, VoiceInterface {
    //三种车牌识别模式
    @BindView(R.id.face_real_time)
    TextView faceRealTime;
    @BindView(R.id.face_take_photo)
    TextView faceTakePhoto;
    int currentId = 0;
    List<Integer> viewIds;
    int indexSelected = 0;
    //默认没有进入过远程协助
    Context context;
    RegModePresenter regModePresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_face_mode);
        context = this;
        ButterKnife.bind(this);
        regModePresenter = new RegModePresenter(this);
        initData();
        stateTag();
    }


    private void initData() {
        viewIds = new ArrayList<>();
        currentId = R.id.face_real_time;
        viewIds.add(R.id.face_real_time);
        viewIds.add(R.id.face_take_photo);
    }

    /**
     * 设置图片背景
     *
     * @author jack
     * create at 2016/11/21 10:15
     */
    private void stateTag() {
        if (currentId == R.id.face_real_time) {
            faceRealTime.setTextColor(Color.BLACK);
            faceTakePhoto.setTextColor(Color.WHITE);
            faceRealTime.setSelected(true);
            faceTakePhoto.setSelected(false);
        } else if (currentId == R.id.face_take_photo) {
            faceRealTime.setTextColor(Color.WHITE);
            faceTakePhoto.setTextColor(Color.BLACK);
            faceRealTime.setSelected(false);
            faceTakePhoto.setSelected(true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        setTouchInterfaceListener(this);
        setVoiceInterfaceListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        setTouchInterfaceListener(null);
        setVoiceInterfaceListener(null);
    }

    @Override
    public void doForwardTouch() {
        if (indexSelected < viewIds.size() - 1) {
            indexSelected++;
            currentId = viewIds.get(indexSelected);
            stateTag();
        }
    }

    @Override
    public void doBackwardTouch() {
        if (indexSelected > 0) {
            indexSelected--;
            currentId = viewIds.get(indexSelected);
            stateTag();
        }
    }

    @Override
    public void doClickTouch() {
        if (currentId == R.id.face_real_time) {
            regModePresenter.jumpFace(true);
        } else if (currentId == R.id.face_take_photo) {
            regModePresenter.jumpFace(false);
        }
    }


    @Override
    public void doDoubleTouch() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void dealWithVoice(String data) {
        if (data.contains("实时模式")) {
            regModePresenter.jumpFace(true);
        } else if (data.contains("拍照模式")) {
            regModePresenter.jumpFace(false);
        } else if (data.contains("返回")) {
            finish();
        }
    }
}